package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.util.ProdCateUtil;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;

public class CarryingPlatformAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Autowired
    private IOperateSceneInstService operateSceneInstService;
    @Autowired
    IQuerySceneInstService querySceneInstService;

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        KiteOfferInst offerInst = querySceneInstService.getMainOfferInst(data.getSceneInstId());
        String offerId = offerInst.getOfferId();
        //5G纯数据产品 下拉值仅包含安全子系统，移除通用子系统（100006403）
        if("50040701".equals(offerId)){
            attr.getAttrValues().removeIf(targetAttr -> KiteStringUtils.equalsAny(targetAttr.getAttrValue(), "100006403","100007001"));
        }
        super.after(attr, inst, data);
        //产品变更 需置灰
        if (KiteStringUtils.isEqual(data.getServiceOfferId(), "2826")
            && KiteStringUtils.equals(inst.getSpecId(), ProdCateUtil.getMainMemberProdId(ProdCateUtil.GIFT_DZ5G_PROD))) {
            attr.setIsEdit(KeyConsts.IFTRUE_F);
            operateSceneInstService
                .setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), attr);
        }
    }
}
